<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>论文列表</title>
    <link rel="stylesheet" href="css/conmmon.css">
    <link rel="stylesheet" href="css/blog_list.css">
    <script src="js/jquery.min.js"></script>
</head>

<body>
    <!-- 导航栏 -->
    <div class="nav">
        <img src="img/logo2.jpg" alt="">
        <span class="title">我的论文系统</span>
        <!-- 用来占据中间位置 -->
        <span class="spacer"></span>
        <a href="blog_list.html">主页</a>
        <a href="blog_add.html">写论文</a>
        <a href="javascript:logout()">注销</a>
    </div>
    <!-- 版心 -->
    <div class="container">
        <!-- 左侧个人信息 -->
        <div class="container-left" style="display: none">
            <div class="card">
                <img src="img/avatar.png" class="avtar" alt="">
                <h3>小可爱</h3>
                <a href="http:www.github.com">github 地址</a>
                <div class="counter">
                    <span>文章</span>
                    <span>分类</span>
                </div>
                <div class="counter">
                    <span>2</span>
                    <span>1</span>
                </div>
            </div>
        </div>
        <!-- 右侧内容详情 -->
        <div id="articleList" class="container-right">

        </div>
    </div>
<script>
    function getMyArticleList(){
        jQuery.ajax({
            url:"/article/mylist",
            type:"POST",
            data:{},
            success:function (res){
                if (res.code===200&&res.data.length>0){
                    //拼接得到的list到articleList里面去
                    let arthtml="";
                    for (let i = 0; i < res.data.length; i++) {
                        let art=res.data[i];
                        arthtml+='<div class="blog">';
                        arthtml+='<div class="title">'+art.title+'</div>';
                        arthtml+='<div class="date">'+art.createtime+'</div>';
                        arthtml+='<div class="desc">'+art.content+'</div>';
                        arthtml+='</div>';
                        arthtml+='<a href="blog_content.html?id='+art.id+'" class="detail">查看全文 &gt;&gt;</a>&nbsp;&nbsp;';
                        arthtml+='<a href="blog_edit.html?id='+art.id+'" class="detail">修改 &gt;&gt;</a>&nbsp;&nbsp;';
                        arthtml+='<a href="javascript:del('+art.id+')" class="detail">删除 &gt;&gt;</a>';
                        arthtml+='</div>';
                    }
                    jQuery("#articleList").html(arthtml);
                }else {
                    jQuery("#articleList").html("<h2 style='margin-left: 100px;margin-top: 100px'>暂无文章</h2>")
                }
            }
        })
    }
    getMyArticleList();
    function del(id){
        if (confirm("确认删除?")){
            jQuery.ajax({
                url:"/article/del",
                type: "POST",
                data: {"id":id},
                success:function (res){
                    if (res.code===200&&res.data===1){
                        alert("删除很成功!");
                        location.href=location.href;
                    }else {
                        alert("删除失败-》"+res.msg);
                    }
                }
            })
        }
    }
</script>
</body>

</html>